﻿@using System.Globalization
@inherits SsoLayoutComponentBase
@inject IJSRuntime JS

<CascadingValue Value="LanguageProvider">
    <MApp>
        <MErrorHandler OnHandle=OnErrorAsync>
            <MMain Style="background:url('./img/login/login_bg.png');background-size: cover;">
                <div class="d-flex flex-column full-height">
                    <MRow>
                        <MCol Offset="2" Md="2" Class="mt-12">
                            <image style="height:40px;"
                                   src="https://cdn.masastack.com/stack/images/logo/MASAStack/logo-h-en.png?x-oss-process=image/resize,w_200">
                            </image>
                        </MCol>
                        <MCol Offset="6" Class="mt-14">
                            <MButton Class="rounded-pill" Color="white" OnClick="ChangeLanguage">
                                <MIcon Left Dark>
                                    mdi-swap-horizontal
                                </MIcon>
                                @(LanguageProvider.Culture.Name == "en-US" ? "中文" : "EN")
                            </MButton>
                        </MCol>
                    </MRow>
                    <MRow Class="flex-grow-1">
                        <MCol Md=12 Sm=12 Class="d-flex justify-center align-center">
                            @Body
                        </MCol>
                    </MRow>
                    <MRow Justify="JustifyTypes.End" Class="mb-8">
                        <MCol Class="text-center" Align="AlignTypes.End">
                            <a href="https://beian.miit.gov.cn/" target="_blank" class="white--text"
                               style="text-decoration:none;font-size:14px;">浙ICP备2021013592号-1</a>
                        </MCol>
                    </MRow>
                </div>
            </MMain>
        </MErrorHandler>
    </MApp>
</CascadingValue>

@code {

    void ChangeLanguage(){
        string _targetCulture = "";
        if (LanguageProvider.Culture.Name == "en-US")
        {
            _targetCulture = "zh-CN";
        }
        else
        {
            _targetCulture = "en-US";
        }
        LanguageProvider.SetCulture(new CultureInfo(_targetCulture));
    }

    async Task<bool> OnErrorAsync(Exception e){
        await PopupService.EnqueueSnackbarAsync(e.Message, AlertTypes.Error);
        await JS.InvokeVoidAsync("console.log", $"error: {e.ToString()}");
        return true;
    }
}